package com.watering.plan;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TimePicker;
import android.widget.Toast;

public class DayRestrictions  extends Activity {
	public int hour_s;
	public int min_s;
	public int hour_f;
	public int min_f;
	TimePicker tp1;
	TimePicker tp2;
	Toast ts;
	Base bs;
	
	public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
         setContentView(R.layout.dayrestriction);
         
         ts =  Toast.makeText(this, R.string.day_help, Toast.LENGTH_SHORT);
         ts.setDuration(Toast.LENGTH_LONG);
         
         ImageView img = (ImageView)findViewById(R.id.helpbutton);
         img.setOnClickListener(new OnClickListener() {
	         public void onClick(View v) {
	        	ts.show();
	         }
	     });
         
         tp1 = new TimePicker(this);
         tp1 = (TimePicker)findViewById(R.id.TimePicker1);
         tp2 = new TimePicker(this);
         tp2 = (TimePicker)findViewById(R.id.TimePicker2);
         bs = new Base(this);
         
	     Button SaveButton = (Button) findViewById(R.id.savebutton);
	     SaveButton.setOnClickListener(new OnClickListener() {
	         public void onClick(View v) {
	        	 hour_s = tp1.getCurrentHour();
	        	 hour_f = tp2.getCurrentHour();
	        	 min_s = tp1.getCurrentMinute();
	        	 min_f = tp2.getCurrentMinute();
	        	 
	     	   
	    	    try{
	    				bs.createDataBase();
	    				bs.openDataBase();
	    			//	ts.setText("ceva" +bs.getRestriction());
	    				bs.addRestriction(0,hour_s,min_s,hour_f,min_f,0,0,0,0);
	    				bs.close();
	    				
	    		}catch(Exception e){
	    			ts.setText(e.toString());
	    			ts.show();
	    		}
	    		finish();
	         }
	     });
	}  
}